package vip.mall.modular.specialist.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.mall.common.result.CommonResult;
import vip.mall.modular.specialist.entity.Specialist;
import vip.mall.modular.specialist.params.AddSpecialistParams;
import vip.mall.modular.specialist.service.SpecialistService;

import java.util.List;

/**
 * @author Asus
 * @Date 2025/2/10 15:28
 * @Descripition
 */

@RestController
@RequestMapping("/specialist")
@Tag(name = "规格业务")
public class SpecialistController {
    @Resource
    private SpecialistService specialistService;

    @PostMapping("/add")
    @Operation(summary = "增加规格")
    public CommonResult add(@RequestBody AddSpecialistParams addSpecialistParams){
        specialistService.add(addSpecialistParams);
        return CommonResult.success("增加规格成功");
    }

    @PostMapping("/delete")
    @Operation(summary = "删除规格")
    public CommonResult delete(Integer id){
        specialistService.removeById(id);
        return CommonResult.success("删除成功");
    }

    @PostMapping("/updateInfo")
    @Operation(summary = "修改规格信息")
    public CommonResult updateInfo(@RequestBody Specialist specialist){
        specialistService.updateById(specialist);
        return CommonResult.success("修改成功");
    }

    @PostMapping("/list")
    @Operation(summary = "查询规格信息列表")
    public CommonResult list(){
        List<Specialist> list = specialistService.list();
        return CommonResult.success(list);
    }

    @PostMapping("/findName")
    @Operation(summary = "根据规格名称模糊查询")
    public CommonResult findName(String specName){
        List<Specialist> specialists = specialistService.findName(specName);
        return CommonResult.success(specialists);
    }
}
